package com.xywy.beautyand.ACT;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.VolleyError;
import com.xywy.beautyand.R;
import com.xywy.beautyand.base.BaseActivity;
import com.xywy.beautyand.bean.FeedBack;
import com.xywy.beautyand.bean.User;
import com.xywy.beautyand.util.Constants;
import com.xywy.beautyand.util.UIUtil;
import com.xywy.beautyand.vollery.OnVolleyResponseListener;
import com.xywy.beautyand.vollery.PostRequest;

/**
 * *****************************************  
* @Title: SetAboutSugarDoctorFeedBackActivity.java 
* @Package com.xywy.performgirlsandroid.act 
* @Description: TODO(意见反馈) 
* @author smz
* @date 2014-12-30 下午6:53:17 
* @version V1.0   
*******************************************
 */
public class SetAboutSugarDoctorFeedBackActivity extends BaseActivity {

	private Button btn_feedback;
	private EditText content_feedback;
	private OnFocusChangeListener mOnFocusChangeListener = new OnFocusChangeListener() {
		@Override
		public void onFocusChange(View v, boolean hasFocus) {
			EditText textView = (EditText) v;
			String hint;
			if (hasFocus) {
				hint = textView.getHint().toString();
				textView.setTag(hint);
				textView.setHint("");
			} else {
				hint = textView.getTag().toString();
				textView.setHint(hint);
			}
		}
	};
	private RelativeLayout left_img;
	private TextView middle_title;

	@Override
	protected void initView(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		setContentView(R.layout.activity_set_about_sugardoctor_feedback);
		left_img = (RelativeLayout) findViewById(R.id.left_img);
		middle_title = (TextView) findViewById(R.id.middle_title);
		middle_title.setText("意见反馈");
		content_feedback = (EditText) findViewById(R.id.content_feedback);
		content_feedback.setOnFocusChangeListener(mOnFocusChangeListener);
		btn_feedback = (Button) findViewById(R.id.btn_feedback);
	}

	@Override
	protected void initListener() {
		left_img.setOnClickListener(this);
		btn_feedback.setOnClickListener(this);
	}

	@Override
	public void onClick(View view) {
		super.onClick(view);
		switch (view.getId()) {
		case R.id.left_img:
			finish();
			break;
		case R.id.btn_feedback:
			submit();
			break;
		default:
			break;
		}
	}

	private void submit() {
		// TODO Auto-generated method stub
		String content = content_feedback.getText().toString().trim();
		PostRequest<FeedBack> postRequest = new PostRequest<FeedBack>(
				Constants.getUrl("TangAndroid", "user_feedback"), FeedBack.class,
				new OnVolleyResponseListener<FeedBack>() {

					@Override
					public void onError(VolleyError volleyError) {
						// TODO Auto-generated method stub
						UIUtil.DissDialog(context, waittingDialog);
						Toast.makeText(context, "提交失败！", Toast.LENGTH_SHORT)
								.show();

					}

					@Override
					public void onSuccess(FeedBack response) {
						// TODO Auto-generated method stub
						UIUtil.DissDialog(context, waittingDialog);
						FeedBack.getFeedbackInstance().setFeedBack(response);
						if (response != null) {
							if (response.getState() == 200) {
								// Intent intent = new Intent(context,
								// Se.class);
								// startActivity(intent);
								Toast.makeText(context, "提交成功！",
										Toast.LENGTH_SHORT).show();

								finish();
							} else {
								UIUtil.showToast(context, response.getError());
							}
						}

					}
				});
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("userid", User.getInstance(context).getUserid());// userid
		params.put("apptype", "10002");// apptype
		try {
			params.put("content", URLEncoder.encode(content, "UTF-8")
					.toString());
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		postRequest.setParams(params);
		executeRequest(postRequest);

	}

	@Override
	protected void initData() {

	}
}